package com.antu.first.web.frontend;

import com.alibaba.fastjson.JSON;
import com.antu.first.bean.DiscountCoupon;
import com.antu.first.bean.Hotel;
import com.antu.first.bean.User;
import com.antu.first.dao.HotelDao;
import com.antu.first.service.UserService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/userController",produces = "text/plain;charset=utf-8")
public class UserController {
    Map<String,Object> modelMap=new HashMap<String,Object>();
    private HotelDao hotelDao;
    @Autowired
    private UserService userService;
    //用户根据优惠券状态查询优惠券
   /* @RequestMapping(value = "/selectDidcountCouponByState",method = RequestMethod.GET)
    @ResponseBody
    public String selectDidcountCouponByState(int dStatus, HttpServletRequest request){
        User user=(User) request.getSession().getAttribute("user");
        System.out.println("contr"+user);
        DiscountCoupon discountCoupon=new DiscountCoupon();
        discountCoupon.setUser(user);
        discountCoupon.setdStatus(dStatus);
        try {
            // modelMap=userService.selectUserDiscountByIdAndState(discountCoupon);
        } catch (Exception e) {
            modelMap.put("errMsg","用户查询优惠券错误，请稍后再试");
            e.printStackTrace();
        }
        String jsonStr= JSON.toJSONString(modelMap);
        return jsonStr;
    }*/
    @RequestMapping(value = "/selectAllDiscountCouponByUid")
    //用户根据优惠券状态查询优惠券
    @ResponseBody
    public String selectAllDiscountCouponByUid(HttpServletRequest request){
        User user=(User) request.getSession().getAttribute("user");
        Date date=new Date();
        DiscountCoupon discountCoupon=new DiscountCoupon();
        discountCoupon.setdStart(date);
        discountCoupon.setUser(user);
        try {
            modelMap=userService.selectAllDiscountCouponByUid(discountCoupon);
            System.out.println(modelMap);
        } catch (Exception e) {
            modelMap.put("errMsg","用户查询优惠券错误");
            e.printStackTrace();
        }
        String jsonStr= JSON.toJSONString(modelMap);
        return jsonStr;
    }
}